package cn.wd.web.controller;


import cn.wd.domain.BulletMsgSensitive;
import cn.wd.page.PageResult;
import cn.wd.qo.QueryObject;
import cn.wd.service.IBulletMsgSensitiveService;
import cn.wd.vo.JsonResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/bulletmsgsensitive")
public class BulletMsgSensitiveController {
    
    private final IBulletMsgSensitiveService service;

    public BulletMsgSensitiveController(IBulletMsgSensitiveService service) {
        this.service = service;
    }

    @RequestMapping("/list")
    public JsonResult<PageResult<BulletMsgSensitive>> query(QueryObject qo) {
        return JsonResult.success(service.query(qo));
    }

    @RequestMapping("/all")
    public JsonResult<List<BulletMsgSensitive>> all() {
        return JsonResult.success(service.selectAll());
    }

    @RequestMapping("/saveOrUpdate")
    public JsonResult<?> saveOrUpdate(@RequestBody BulletMsgSensitive bulletMsgSensitive) {
        if (bulletMsgSensitive.getId() != null) {
            service.updateById(bulletMsgSensitive);
        } else {
            service.save(bulletMsgSensitive);
        }

        return JsonResult.success();
    }

    @RequestMapping("/delete")
    public JsonResult<?> delete(Long id) {
        if (id == null) {
            return JsonResult.failed("删除的 id 不能为空!");
        }

        service.deleteById(id);
        return JsonResult.success();
    }
}
